/*
* @author : TF-BJ-C064
* @creation : 2014-6-9 下午4:04:48
* @description : 
*
*/

package com.service.impl;

import java.util.List;

import com.base.PageBean;
import com.base.UserBean;
import com.bean.ParkManager;
import com.bean.Userinfo;
import com.dao.ParkManagerDao;
import com.service.ParkManagerService;
import com.util.EncoderHandler;
import com.util.GUtil;

public class ParkManagerServiceImpl implements ParkManagerService {

	private ParkManagerDao dao;
	
	@Override
	public ParkManager login(ParkManager pk, String ip) throws Exception {
		return dao.login(pk, ip, null, null);
	}

	//通过token登录
	@Override
	public ParkManager login(Long userId, String token, String ip)
			throws Exception {
		return dao.login(null, ip, token, userId);
	}

	@Override
	public ParkManager get(Long id) throws Exception {
		return dao.get(id);
	}
	
	@Override
	public ParkManager getByToken(String token, Long userId) throws Exception {
		if(token==null || userId==null)
			throw new Exception("token and usercode cannot be null.");
		if(token.isEmpty() )
			throw new Exception("token and usercode cannot be empty.");
		return dao.getByToken(token, userId);
	}


	@Override
	public List<ParkManager> query(ParkManager parkManager, Long parkId) throws Exception {
		return dao.query(parkManager, parkId);
	}

	/**
	 * 修改用户信息：
	 * 修改内容：
	 * 
	 */
	@Override
	public String update(ParkManager parkManager, Integer []parkIds) throws Exception {
		ParkManager pkm = this.get(parkManager.getUserId());
		if(pkm==null)
			return GUtil.FAILE;
		//photo
		if(parkManager.getPhoto()!=null && !parkManager.getPhoto().trim().isEmpty()){
			pkm.setPhoto(parkManager.getPhoto());
		}
		//密码
		if(parkManager.getUserPasswd()!=null && !parkManager.getUserPasswd().trim().isEmpty()){
			pkm.setUserPasswd( EncoderHandler.EncoderPasswordBase64Md5(parkManager.getUserPasswd().trim()));
		}
		//用户真实姓名
		if(parkManager.getRealName()!=null && !parkManager.getRealName().trim().isEmpty())
			pkm.setRealName(parkManager.getRealName().trim());
		//角色
		if(parkManager.getRole()!=null )
			pkm.setRole(parkManager.getRole());
		//手机号
		if(parkManager.getPhone()!=null && !parkManager.getPhone().trim().isEmpty())
			pkm.setPhone(parkManager.getPhone().trim());
		//用户状态
		if(parkManager.getStatus()!=null )
			pkm.setStatus(parkManager.getStatus());
		
		return dao.update(pkm, parkIds);
	}
	
	@Override
	public List getMyParkUsers(ParkManager pm) throws Exception {
		return dao.getMyParkUsers(pm, null);
	}
	@Override
	public List getMyParkUsers(ParkManager pm, ParkManager queryCriteriaPM)
			throws Exception {
		return dao.getMyParkUsers(pm, queryCriteriaPM);
	}

	
	public List findByProperty(String propertyName, Object value) throws Exception {
		return dao.findByProperty(propertyName, value);
	}

	@Override
	public String add(ParkManager parkManager, Integer[] parkIds) throws Exception {
		return dao.add(parkManager, parkIds);
	}
	public String add(ParkManager parkManager){
		return dao.add(parkManager);
	}
	@Override
	public String delete(Long id,Integer flag) throws Exception {
		return dao.delete(id,flag);
	}

	/**
	 * @return the dao
	 */
	public ParkManagerDao getDao() {
		return dao;
	}

	/**
	 * @param dao the dao to set
	 */
	public void setDao(ParkManagerDao dao) {
		this.dao = dao;
	}

	@Override
	public List<ParkManager> findbyrole(ParkManager manager,PageBean page) {
		List<ParkManager> list = dao.find((ParkManager) manager, page);
		if(list==null || list.size()==0)
			return null;
		return list;
	}

	@Override
	public String lock(Long id, Integer flag) {
		return dao.lock(id, flag);
	}

	@Override
	public String update(ParkManager parkManager) {
		return dao.update(parkManager);
	}

	@Override
	public String save(ParkManager parkManager) {
		return dao.add(parkManager);
	}

	@Override
	public String findNames(String name) {
		return dao.findNames(name);
	}


}
